#define _CRT_SECURE_NO_WARNINGS 1
#include"Head.h"

class Solution1 {
public:
    int lengthOfLastWord(string s) {
        string s_rev(s.rbegin(), s.rend());
        int i = 0;
        while (i < s_rev.size() && s_rev[i] == ' ')
            ++i;
        int count = 0;
        while (i < s_rev.size() && s_rev[i] != ' ')
            ++i, ++count;
        return count;
    }
};

class Solution2 {
public:
    int lengthOfLastWord(string s) {
        int i = s.size() - 1;
        while (i >= 0 && s[i] == ' ')
            --i;
        int count = 0;
        while (i >= 0 && s[i] != ' ')
            --i, ++count;
        return count;
    }
};
